<?php

defined('In33hao') or exit('Access Invalid!');
class indexControl{

    public function indexOp() {
        if (isset($_GET["echostr"])) {
            $this->valid();
        }
    }


    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if ($this->checkSignature()) {
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $model = Model('setting');
        $info = $model->getListSetting();
        $token = $info['hao_webchat_token'];
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        if ($tmpStr == $signature) {
            return true;
        } else {
            return false;
        }
    }


}
